package com.rainner.app.server;

import java.sql.SQLException;
import java.util.List;

import com.rainner.app.javabean.BrrowedBookBean;
import com.rainner.app.util.dbutil.BaseService;

public class BrrowedBookServer extends BaseService<BrrowedBookBean> {
	/**
	 * 借走书籍
	 * 
	 * @param bean
	 * @return
	 * @throws SQLException
	 */
	public boolean brrowedBook(BrrowedBookBean bean) throws SQLException {
		String sqlInsert = "insert into BrrowedBook(ReaderUsername,BookID,BorrowedBookNumber,BorrowedDate) values(?,?,?,?)";
		return super.update(sqlInsert, bean.getReaderUsername(), bean.getBookID(), bean.getBorrowedBookNumber(), bean.getBorrowedDate());
	}

	/**
	 * 
	 * @param readerUsername
	 * @return
	 * @throws SQLException
	 */
	public List<BrrowedBookBean> listBook(String readerUsername) throws SQLException {
		String sqlSelect = "select * from BrrowedBook where ReaderUsername = ? ";
		return super.query(sqlSelect, readerUsername);
	}

	/**
	 * 归还书籍
	 * 
	 * @param bookId
	 * @param readerUsername
	 * @return
	 * @throws SQLException
	 */
	public boolean backBook(String bookId, String readerUsername) throws SQLException {
		String sqlDelete = "delete from BrrowedBook where BookId = ? and ReaderUsername = ?";
		return super.update(sqlDelete, bookId, readerUsername);
	}
}
